/**
 * Created by Administrator on 2016/6/30 0030.
 */
var time_swiper;
$(document).ready(function () {
    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = b_version.split(";");
    var trim_Version = version[1].replace(/[ ]/g, "");
    if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE6.0") {
        content_start();
        circular_mini();
        content_btn();
        carousel();
        mouseIE();
    }
    else if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE7.0") {
        content_start();
        circular_mini();
        content_btn();
        carousel();
        mouseIE();
    }
    else if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE8.0") {
        content_start();
        circular_mini();
        content_btn();
        carousel();
        mouseIE();
    } else {
        circular_rotate();
        mouse();
    }
});

function circular_rotate() {
    $(".one-circular-mini").each(function (index) {
        var obj = $(this);
        var num;
        obj.click(function () {
            $(".one-circular-mini").unbind();
            $(".one-circular-words").css("width", "0");

            mySwiper.stopAutoplay();/*******/

            $(".one-circular-mini").each(function (i) {
                if ($(this).css("background-color") == "rgb(225, 81, 91)") {
                    num = i;
                }
                $(this).css({"background-color": "#ccc", "color": "#010101"})
            });
            obj.css({"background-color": "#e1515b", "color": "#fff"});
            if (index == 0) {
                $(".one-circular-words").find("div").html("零投入快速拥有企业专属平台");
                circular_rotate_animate($(this).parent(), num, 0)
            } else if (index == 1) {
                $(".one-circular-words").find("div").html("无起订量享受电商集采价格优势");
                circular_rotate_animate($(this).parent(), num, 23)
            } else if (index == 2) {
                $(".one-circular-words").find("div").html("零投库存管理减少浪费降低脚本");
                circular_rotate_animate($(this).parent(), num, 46)
            } else if (index == 3) {
                $(".one-circular-words").find("div").html("服务高效便捷行业领先专业水平 ");
                circular_rotate_animate($(this).parent(), num, 69)
            } else if (index == 4) {
                $(".one-circular-words").find("div").html("数据实时查询消费明白管理放心 ");
                circular_rotate_animate($(this).parent(), num, 92)
            } else if (index == 5) {
                $(".one-circular-words").find("div").html("海量产品自选提升满意度");
                circular_rotate_animate($(this).parent(), num, 115)
            }
        });
    });
}

function circular_rotate_animate(obj, num, rotate) {
    var rotate_start;
    var condition;
    var speed = 10;
    if (num == 0) {
        rotate_start = 0;
    } else if (num == 1) {
        rotate_start = 23;
    } else if (num == 2) {
        rotate_start = 46;
    } else if (num == 3) {
        rotate_start = 69;
    } else if (num == 4) {
        rotate_start = 92;
    } else if (num == 5) {
        rotate_start = 115;
    }
    if (Math.abs(rotate_start - rotate) > 70) {
        speed = 5;
    }
    var time = setInterval(function () {
        if (rotate > rotate_start) {
            rotate_start++;
            condition = 1;
        } else if (rotate < rotate_start) {
            rotate_start--;
            condition = 0;
        }
        obj.css({
            "transform": "rotate(-" + rotate_start + "deg)",
            "-ms-transform": "rotate(-" + rotate_start + "deg)",
            "-webkit-transform": "rotate(-" + rotate_start + "deg)",
            "-o-transform": "rotate(-" + rotate_start + "deg)",
            "-moz-transform": "rotate(-" + rotate_start + "deg)"
        });
        obj.find(".one-circular-mini").css({
            "transform": "rotate(" + rotate_start + "deg)",
            "-ms-transform": "rotate(" + rotate_start + "deg)",
            "-webkit-transform": "rotate(" + rotate_start + "deg)",
            "-o-transform": "rotate(" + rotate_start + "deg)",
            "-moz-transform": "rotate(" + rotate_start + "deg)"
        });
        if (rotate_start >= rotate && condition == 1) {
            clearInterval(time);
            $(".one-circular-words").animate({
                "width": "325px"
            }, 400, function () {
                circular_rotate();
                mySwiper.startAutoplay();
            })
        } else if (rotate_start <= rotate && condition == 0) {
            clearInterval(time);
            $(".one-circular-words").animate({
                "width": "325px"
            }, 400, function () {
                circular_rotate();
                mySwiper.startAutoplay();
            })
        }
    }, speed);
}

function mouse() {
    var elem = $(".two-right-tittle").find("ul").find("li").find("a");
    elem.mouseenter(function () {
        mySwiper.stopAutoplay();
    });
    elem.mouseleave(function () {
        mySwiper.startAutoplay();
    })
}

/***************  IE <9 *****************/
function content_start() {
    $(".swiper-slide").each(function (number) {
        $(".choice-btn").unbind();
        if (number == 0) {
            $(this).css("display", "block");
        }
    });
}

function content_btn() {
    $(".swiper-button-next").click(function () {
        $(".swiper-button-prev").css("display", "block");
        clearTimeout(time_swiper);
        $(".choice-btn").unbind();
        var num = "";
        var obj_next = "";
        $(".swiper-slide").each(function (index) {
            if ($(this).css("display") == "block") {
                if (index >= 4) {
                    return
                } else {
                    if (index == 3) {
                        $(".swiper-button-next").css("display", "none");
                    }
                    obj_next = $(this);
                    num = index;
                }
            }
        });
        if (num >= 0) {
            $(".swiper-slide").each(function (i) {
                if (i == num + 1) {
                    obj_next.css("display", "none");
                    $(this).css({"left": "0", "display": "block"});
                }
            })
        }
        content_btn();
        carousel();
    });
    $(".swiper-button-prev").click(function () {
        $(".swiper-button-next").css("display", "block");
        clearTimeout(time_swiper);
        $(".choice-btn").unbind();
        var num = "";
        var obj_next = "";
        $(".swiper-slide").each(function (index) {
            if ($(this).css("display") == "block") {
                if (index <= 0) {
                    return
                } else {
                    if (index == 1) {
                        $(".swiper-button-prev").css("display", "none");
                    }
                    obj_next = $(this);
                    num = index;
                }
            }
        });
        if (num >= 0) {
            $(".swiper-slide").each(function (i) {
                if (i == num - 1) {
                    obj_next.css("display", "none");
                    $(this).css({"left": "0", "display": "block"});
                }
            })
        }
        content_btn();
        carousel();
    })
}

function carousel() {
    time_swiper = setTimeout(function () {
        $(".choice-btn").unbind();
        var num;
        $(".swiper-slide").each(function (index) {
            if ($(this).css("display") == "block") {
                num = index + 1;
                if (num > 4) {
                    num = 0
                }
            }
        });
        carousel_ainimate(num);
    }, 5000);
}

function carousel_ainimate(num) {
    if (num > 0) {
        $(".swiper-button-prev").css("display", "block");
    }
    if (num < 4) {
        $(".swiper-button-next").css("display", "block");
    }
    if (num == 4) {
        $(".swiper-button-next").css("display", "none");
    }
    if (num == 0) {
        $(".swiper-button-prev").css("display", "none");
    }
    $(".swiper-slide").each(function (i) {
        if (i == num) {
            $(this).css({"display": "block", "left": "0"});
        } else {
            $(this).css("display", "none");
        }
    });
    content_btn();
    carousel();
}

function circular_mini() {
    var obj = $(".one-circular-mini");
    var num;
    obj.each(function (index) {
        $(this).click(function () {
            clearTimeout(time_swiper);
            var obj_this = $(this);
            var words = $(".one-circular-words");
            obj.css({"background": "#ccc", "color": "#010101"});
            obj_this.css({"background": " #e1515b", "color": "#fff"});
            if (index == 0) {
                words.find("div").html("零投入快速拥有企业专属平台");
            } else if (index == 1) {
                words.find("div").html("无起订量享受电商集采价格优势");
            } else if (index == 2) {
                words.find("div").html("零投库存管理减少浪费降低脚本");
            } else if (index == 3) {
                words.find("div").html("服务高效便捷行业领先专业水平 ");
            } else if (index == 4) {
                words.find("div").html("数据实时查询消费明白管理放心 ");
            } else if (index == 5) {
                words.find("div").html("海量产品自选提升满意度");
            }
            carousel();
        });
    })
}

function mouseIE() {
    var elem = $(".two-right-tittle").find("ul").find("li").find("a");
    elem.mouseenter(function () {
        clearTimeout(time_swiper);
    });
    elem.mouseleave(function () {
        carousel();
    })
}